var loadAnim = '<p><img src="img/ajax-loader.gif" width="200" align="center" /></p>';
// "autorun"
$(function() {
	$('#register').click(function() {
		$.post("php/bb.php", { "register" : "true" },
			function(res){
				//$('#login').html(res);
				$(res).dialog({
					modal: true,
					resizeable: false
				});
				$('#regbtn').click(function(){
					alert($('form.register').serialize());
					$.post("php/bb.php?register=true&"+$('form.register').serialize()), {},
						function(res) {
							if (res=="OK") alert('xxx');
						}
				});
			}
		);
	});

	$('#login').click(function() {
		$.post("php/bb.php", { "uname" : $('.uname').value, "pass" : $('.pass').value },
			function(res){
				//$('#login').html(res);
				$(res).dialog({
					modal: true,
					resizeable: false
				});
			}
		);
	});
	$('form.new').click(function() {
		XC,ReplyTo(0);
	});
});


/*
		Spremenljivke in funkcije
*/
var XC = {};
var Util = {};

XC.ReplyTo = function(id) {
	$.post("php/bb.php", { "replyto" : id}, function(res) {
		$('#message_'+id+'_reply').html(res);
		$('#message_'+id+'_reply .head .title input').keyup(function() {
			if (Util.IsURL(this.value) == true) {
				clearTimeout(XC.FillFromURLtimer);
				XC.FillFromURLtimer = setTimeout("XC.FillFromURL('"+id+"','php/proxy.php?p="+this.value+"');", 1000)
			}
		});
	});
};

XC.FillFromURLtimer = -1
XC.FillFromURL = function(messageId, url) {
	$.get(url, function(data) {
		$('#message_'+messageId+'_reply .body').css('display', 'block');
		//$('#message_'+messageId+'_reply .hlp1').html(data);
		//$('#message_'+messageId+'_reply textarea').html(data);
		//$('#message_'+messageId+'_reply .hlp1 meta').html(data);
		Util.GetMetaDescription(data);
	});
}
Util.GetMetaDescription = function (htmlString) {
	var expression = /[-a-zA-Z0-9@:%_\+.~#?&//=]{2,256}\.[a-z]{2,4}\b(\/[-a-zA-Z0-9@:%_\+.~#?&//=]*)?/gi
	//var regex = new RegExp(expression);
	//t = regex.test(s);
	return htmlString;
}
Util.IsURL = function (s) {
	var expression = /[-a-zA-Z0-9@:%_\+.~#?&//=]{2,256}\.[a-z]{2,4}\b(\/[-a-zA-Z0-9@:%_\+.~#?&//=]*)?/gi
	//var expression = /[-a-zA-Z0-9@:%_\+.~#?&//=]{2,256}\.[a-z]{2,4}\b(\/[-a-zA-Z0-9@:%_\+.~#?&//=]*)?/gi;
	var regex = new RegExp(expression);
	t = regex.test(s);
	return t;
}